From 5586a0a3e1cc3834660a30f53c760f40cd0a3d09 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Sun, 3 Sep 2006 02:44:15 +0000 Subject: [PATCH] Add advanced tsearch2 config testing, attempt to force correct locale. --- includes/DatabasePostgres.php | 44 +++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index f96d931c53..0dbfd2473f 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -90,7 +90,8 @@ class DatabasePostgres extends Database { $this->mOpened = true; ## If this is the initial connection, setup the schema stuff and possibly create the user if (defined('MEDIAWIKI_INSTALL')) { - global $wgDBname, $wgDBuser, $wgDBpass, $wgDBsuperuser, $wgDBmwschema, $wgDBts2schema; + global $wgDBname, $wgDBuser, $wgDBpass, $wgDBsuperuser, $wgDBmwschema, + $wgDBts2schema, $wgDBts2locale; print "OK\n"; $safeuser = $this->quote_ident($wgDBuser); @@ -230,8 +231,10 @@ class DatabasePostgres extends Database { print "OK\n"; ## Does this user have the rights to the tsearch2 tables? + $ctype = pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0); print "
  • Checking tsearch2 permissions..."; - $SQL = "SELECT 1 FROM $wgDBts2schema.pg_ts_cfg"; + $SQL = "SELECT ts_name FROM $wgDBts2schema.pg_ts_cfg WHERE locale = '$ctype'"; + $SQL .= " ORDER BY CASE WHEN ts_name <> 'default' THEN 1 ELSE 0 END"; error_reporting( 0 ); $res = $this->doQuery($SQL); error_reporting( E_ALL ); @@ -241,6 +244,43 @@ class DatabasePostgres extends Database { } print "OK
  • "; + ## Will the current locale work? Can we force it to? + print "
  • Verifying tsearch2 locale with $ctype..."; + $rows = $this->numRows($res); + $resetlocale = 0; + if (!$rows) { + print "not found
  • \n"; + print "
  • Attempting to set default tsearch2 locale to \"$ctype\"..."; + $resetlocale = 1; + } + else { + $tsname = pg_fetch_result($res, 0, 0); + if ($tsname != 'default') { + print "not set to default ($tsname)"; + print "
  • Attempting to change tsearch2 default locale to \"$ctype\"..."; + $resetlocale = 1; + } + } + if ($resetlocale) { + $SQL = "UPDATE $wgDBts2schema.pg_ts_cfg SET locale = '$ctype' WHERE ts_name = 'default'"; + $res = $this->doQuery($SQL); + if (!$res) { + print "FAILED. "; + print "Please make sure that the locale in pg_ts_cfg for \"default\" is set to \"ctype\"
  • \n"; + dieout(""); + } + print "OK"; + } + + ## Final test: try out a simple tsearch2 query + $SQL = "SELECT $wgDBts2schema.to_tsvector('default','MediaWiki tsearch2 testing')"; + $res = $this->doQuery($SQL); + if (!$res) { + print "FAILED. Specifically, \"$SQL\" did not work."; + dieout(""); + } + print "OK"; + ## Do we have plpgsql installed? print "
  • Checking for Pl/Pgsql ..."; $SQL = "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'"; -- 2.20.1